package com.wuxianedu.image_loader;

import android.app.Activity;
import android.graphics.Bitmap;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;

import com.nostra13.universalimageloader.cache.disc.naming.HashCodeFileNameGenerator;
import com.nostra13.universalimageloader.cache.memory.impl.LruMemoryCache;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.ImageSize;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
import com.nostra13.universalimageloader.core.decode.BaseImageDecoder;
import com.nostra13.universalimageloader.core.download.BaseImageDownloader;
import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener;
import com.nostra13.universalimageloader.utils.StorageUtils;

import java.io.File;

public class MainActivity extends Activity {

    private ImageView iv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        iv = (ImageView) findViewById(R.id.iv);
        // init();
        //init2();
        init3();
    }

    /**
     * 使用同步
     */
    private void init3() {
        ImageLoader loader = ImageLoader.getInstance();
        String uri = "http://img21.mtime.cn/pi/2012/01/12/164817.41734760_1000X1000.jpg";
        loader.loadImageSync(uri);

    }

    private void init2() {
        ImageLoader loader = ImageLoader.getInstance();
        String uri = "http://img21.mtime.cn/pi/2012/01/12/164817.41734760_1000X1000.jpg";

        //指定图片的大小
        ImageSize targetSize = new ImageSize(80, 50);

        loader.loadImage(uri, targetSize, new SimpleImageLoadingListener() {
            @Override
            public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                iv.setImageBitmap(loadedImage);
                Log.e("------main-------", "---------------" + imageUri);
                Log.e("------main-------", "view:" + view);

            }
        });
    }

    /**
     * 加载网络图片
     */
    private void init() {
        ImageLoader loader = ImageLoader.getInstance();
        String uri = "http://img21.mtime.cn/pi/2012/01/12/164817.41734760_1000X1000.jpg";
        loader.displayImage(uri, iv);
    }


}
